 require 'rextral.rb'


 #RAKE TASKS:
 #CONNECTION TASKS
 task :start_to_connect do
	create_global_connection_file
	puts "SUCCESS...global_connection.csv file has been created in you current working directory./nPlease fill up the options"
 end





 #DB TO DB TRANSFERS:
 task :start_db_to_db_transfer do
	create_db_to_db_transfer_file
	puts "SUCCESS...A configuration file for the DB to DB tranfer has been created in you current working directory./nPlease fill up the options"
 end
 
 task :run_db_to_db_transfer do
       execute_db_to_db_transfer
       puts "SUCCESS...The data was succesfully transferred. Please check the destination database."
 end  

 def create_db_to_db_transfer_file
	config_file = File.new("db_to_db_config.csv","w") 
	config_file.write("SOURCE DETAILS \n")
	config_file.write("database_type,\n")
	config_file.write("database,\n")
	config_file.write("host,\n")
	config_file.write("password,\n")
	config_file.write("username,\n")
	config_file.write("DESTINATION DETAILS \n")
	config_file.write("database_type,\n")
	config_file.write("database,\n")
	config_file.write("host,\n")
	config_file.write("password,\n")
	config_file.write("username,\n")
	config_file.close
 end	 

 def execute_db_to_db_transfer
	get_source_details 
 end



 #LOADING STARTS HERE
 task :learn_load do
	puts "By load we mean transferring data from CSV to SQLite, MySQL or PostgreSQL.\nFor each CSV file mentioned in the config_load file, a separate table will be created having the same name as that of the CSV file.\nAlso, a stats files for each table created and\n also for an entire database will also be generated. All these files will reside in your CURRENT WORKING DIRECTORY."
 end

 task :start_load do
	write_extract_options_to_a_file("loading")
	puts "SUCCESS....\nA file named as load_config.csv has been created \nin your current working directory.\nPlease fill up the options."
 end	

 task :run_load do
	puts "Starting with the loading..." 
	csv_file_list = get_csv_file_list
	load_options = read_load_file.split(",")
	puts "Options extracted from configuration file..."
	puts "Loading data for these options..."
	entry_method_for_process_to_start(csv_file_list)
	puts "SUCCESS...The loading was succesfully completed.\nPlease check the database. \nThere will be a table for each CSV data file mentioned in the CSV file list\n"
 end	






 #EXTRACTION STARTS HERE
 #This rake task is with for creation of the configuration file template.
 task :learn_extract do
	puts "By extract we mean transferring data from SQLite, MySQL or PostgreSQL to CSV.\nFor each table in the database a separate CSV file having name same as that of table will be created.\nAlso, a stats files for each table and\n also for an entire database level will be generated. All these files will reside in your CURRENT WORKING DIRECTORY."
 end

 
 task :run_extract do
	puts "Starting with the extraction..." 
	get_table_data_to_csv
	puts "SUCCESS...The extraction was succesfully completed.\nPlease check your current working directory\nThere will be CSV data files for each table in the given database\n"
 end






 #HORIZONTAL TABLE SPLIT TRANSFORM
 task :start_horizontal_split do
	generate_horizontal_split_config_file
	puts "SUCCESS...The configuration file for the horizontal split has been created."
 end

 task :run_horizontal_split do
	puts "Starting with the horizontal split..."
	execute_horizontal_split
	puts "SUCCESS...The horizontal split has been achieved."
 end





 #COLUMN TRANSFORMS:SIZE AND TYPE
 task :start_column_transform do
	create_column_config_file("transform")
	puts "SUCCESS....\nA file named as column_transform_config.csv has been created \nin your current working directory.\nPlease fill up the options." 
 end

 task :run_column_transform do
	puts "Transforming columns now..."
	perform_transform
	puts "SUCCESS...The columns were succesfully transformed."
 end	 


 
 
 
 #CONSTRAINT TRANSFORMS
 task :start_constraint_transform do
	create_constraint_config
	puts "SUCCESS....\nA file named as constraint_transform_config.csv has been created \nin your current working directory.\nPlease fill up the options."
 end	 
 
 task :run_constraint_transform do
	puts "Extracting the connection options..." 
	puts "Connection established..."
	transform_constraint
 end	 
 
 
 
 
 
 #NORMALIZATION TRANSFORMS:FIRST FORM
 task :learn_normalize_first do
	puts "In the first normal form, we will remove the duplicate columns and will also atomize the multivalue attributes.\n"
 end

 task :start_normalize_first do
	create_first_normalization_config_file
	puts "SUCCESS....\nA file named as first_normalize_config.csv has been created \nin your current working directory.\nPlease fill up the options."
 end

 task :run_normalize_first do
	puts "Starting the normalization:first form now..."
	puts "Reading the config file..."
	normalize_first_form
	puts "SUCCESS...The tables were sucesfully normalized to the first form.Please check the database for the child tables."
 end	





 #DENORMALIZATION TRANSFORMS
 task :learn_denormalize do
	puts "Currently the denormalization support is for merging different tables. In this case we keep the root tables intact."
 end

 task :start_denormalize do
	create_denormalization_config_file
	puts "SUCCESS....\nA file named as denorm_config.csv has been created \nin your current working directory.\nPlease fill up the options."
 end

 task :run_denormalize do
	puts "Options extracted from configuration file..."
	puts "Denormalization started..."
	denormalize_tables
	puts "SUCCESS...Denormalization succesfully completed"
 end	





 #RELATIONSHIP TRANSFORM
 task :start_relation_transform do
	create_relationship_transform_config_file
	puts "SUCCESS...\nA file named relation_transform_config.csv has been created \nin your current working directory.\n"
 end

 task :run_relation_transform do
	puts "Options are extracted from configuration file..."
	puts "Relationship transform started..."
	transform_relationships
	puts "SUCCESS...Relationship transform succesfully completed"
 end

 	 
	 